<?php
class ConfigTab extends ObjectModel 
{
    public $id;
    public $id_editor;
    public $name;
    public $position;
    public $active;
    
    public $label;
    public $description;
    public $lang_iso;
    
	public $date_add;
    public $date_upd;
    
    public static $definition = array(
        'table' => 'pt_config_tab',
        'primary' => 'id_tab',
        'multilang' => true,
        'fields' => array(
            'id_editor' => array(
                'type' => self::TYPE_INT,
                'required' => true, 
                'validate' => 'isUnsignedId'
            ),
            'name' => array(
                'type' => self::TYPE_STRING,
                'required' => true,
                'validate' => 'isGenericName', 
                'size' => 64
            ),
            'position' => array(
                'type' => self::TYPE_INT
            ),
            
            'label' => array(
                'type' => self::TYPE_STRING,
                'required' => true,
                'lang' => true, 
                'validate' => 'isGenericName', 
                'size' => 128
            ),
            'description' => array(
                'type' => self::TYPE_STRING,
                'lang' => true,
                'validate' => 'isString',
            ),
            'lang_iso' => array(
                'type' => self::TYPE_STRING,
                'required' => true,
                'lang' => true, 
                'size' => 2,
                'validate' => 'isGenericName',
            ),
            
            'active' => array(
                'type' => self::TYPE_BOOL,
                'required' => true
            ),
            'date_add' =>  array(
                'type' => self::TYPE_DATE, 
                'validate' => 'isDateFormat'
            ),
			'date_upd' => array(
                'type' => self::TYPE_DATE,
                'validate' => 'isDateFormat'
            )
        )
    );
    
    public static function getConfigTabs ($active = true, $filter = '')
    {
        $sql = '
            SELECT t.*, tl.label, CONCAT(c.`code`, \' \', c.`version`, \' &gt; \', tl.label) AS fullname
            FROM `' . _DB_PREFIX_ . 'pt_config_tab` t
            LEFT JOIN `' . _DB_PREFIX_ . 'pt_config_tab_lang` tl ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '. Context::getContext()->language->id .')
            LEFT JOIN `' . _DB_PREFIX_ . 'pt_theme_editor` e ON (t.`id_editor` = e.`id_editor`)
            LEFT JOIN `' . _DB_PREFIX_ . 'pt_cms` c ON (e.`id_cms` = c.`id_cms`)
            WHERE 1'. ($active ? ' AND t.`active` = 1' : '') . $filter;
        if ($rows = Db :: getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql)) 
        {
            return $rows;
        }
        return array();
    }
}